package com.vader.boot.beanPostProcessor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @author Vader
 * @date 2022/5/12
 **/
@Slf4j
@Component
public class Bean1 {

    @Resource
    private Bean2 bean2;

    static {
        log.info("bean1_init");
    }



    public Bean1(){
        log.info("construct_bea1");
    }


    @Autowired
    public void setBean2(Bean2 bean2) {
        log.info("@Autowired work:{}", bean2);
        this.bean2 = bean2;
    }

    private Bean3 bean3;

    @Resource
    public void setBean3(Bean3 bean3) {
        log.info("@Resource work:{}", bean3);
        this.bean3 = bean3;
    }

    private String home;

    @Autowired
    public void setHome(@Value("${JAVA_HOME}") String home) {
        log.info("@Value work:{}",home);
        this.home = home;
    }

    @PostConstruct
    public void init(){
        log.info("@PostConstruct work");
    }

    @PreDestroy
    public void destroy(){
        log.info("@PreDestroy_work");
    }

    @Override
    public String toString() {
        return "Bean1{" +
                "bean2=" + bean2 +
                ", bean3=" + bean3 +
                ", home='" + home + '\'' +
                '}';
    }
}
